/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import java.util.Map;
/*     */ import java.util.concurrent.ConcurrentHashMap;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DavNames
/*     */ {
/*     */   public static final class DavName
/*     */   {
/*     */     public final int mailbox_id;
/*     */     public final int folder_id;
/*     */     public final String davBaseName;
/*     */     
/*     */     private DavName(int mailbox_id, int folder_id, String davBaseName)
/*     */     {
/*  36 */       this.mailbox_id = mailbox_id;
/*  37 */       this.folder_id = folder_id;
/*  38 */       this.davBaseName = davBaseName;
/*     */     }
/*     */     
/*  41 */     public static DavName create(int mailbox_id, int folder_id, String davBaseName) { return new DavName(mailbox_id, folder_id, davBaseName); }
/*     */     
/*     */ 
/*     */     public String toString()
/*     */     {
/*  46 */       StringBuilder sb = new StringBuilder("DavName:mbox=").append(this.mailbox_id).append(" folder=").append(this.folder_id).append(" name=").append(this.davBaseName);
/*     */       
/*  48 */       return sb.toString();
/*     */     }
/*     */     
/*     */     public int hashCode()
/*     */     {
/*  53 */       return toString().hashCode();
/*     */     }
/*     */     
/*     */     public boolean equals(Object obj)
/*     */     {
/*  58 */       if (this == obj) {
/*  59 */         return true;
/*     */       }
/*  61 */       if (obj == null) {
/*  62 */         return false;
/*     */       }
/*  64 */       if (getClass() != obj.getClass()) {
/*  65 */         return false;
/*     */       }
/*  67 */       DavName other = (DavName)obj;
/*  68 */       return toString().equals(other.toString());
/*     */     }
/*     */   }
/*     */   
/*     */   public static final class MboxAndId {
/*     */     public final int mailbox_id;
/*     */     public final int item_id;
/*     */     
/*     */     private MboxAndId(int mailbox_id, int item_id) {
/*  77 */       this.mailbox_id = mailbox_id;
/*  78 */       this.item_id = item_id;
/*     */     }
/*     */     
/*     */     public static MboxAndId create(int mailbox_id, int item_id) {
/*  82 */       return new MboxAndId(mailbox_id, item_id);
/*     */     }
/*     */     
/*     */     public String toString()
/*     */     {
/*  87 */       StringBuilder sb = new StringBuilder("MboxAndId:mbox=").append(this.mailbox_id).append(" item=").append(this.item_id);
/*  88 */       return sb.toString();
/*     */     }
/*     */     
/*     */     public int hashCode()
/*     */     {
/*  93 */       return toString().hashCode();
/*     */     }
/*     */     
/*     */     public boolean equals(Object obj)
/*     */     {
/*  98 */       if (this == obj) {
/*  99 */         return true;
/*     */       }
/* 101 */       if (obj == null) {
/* 102 */         return false;
/*     */       }
/* 104 */       if (getClass() != obj.getClass()) {
/* 105 */         return false;
/*     */       }
/* 107 */       MboxAndId other = (MboxAndId)obj;
/* 108 */       return toString().equals(other.toString());
/*     */     }
/*     */   }
/*     */   
/* 112 */   private static final Map<DavName, Integer> nameToID = new ConcurrentHashMap();
/* 113 */   private static final Map<MboxAndId, DavName> idToName = new ConcurrentHashMap();
/*     */   
/*     */ 
/*     */ 
/*     */   public static Integer get(DavName davName)
/*     */   {
/* 119 */     Integer ret = (Integer)nameToID.get(davName);
/* 120 */     ZimbraLog.dav.debug("DavNameMap.get '%s' --> id=%d", new Object[] { davName, ret });
/* 121 */     return ret;
/*     */   }
/*     */   
/*     */   public static DavName get(MboxAndId mboxAndId) {
/* 125 */     DavName ret = (DavName)idToName.get(mboxAndId);
/* 126 */     ZimbraLog.dav.debug("DavNameMap.get %s ---> '%s'", new Object[] { mboxAndId, ret });
/* 127 */     return ret;
/*     */   }
/*     */   
/*     */   public static DavName get(int mailbox_id, int item_id)
/*     */   {
/* 132 */     return get(MboxAndId.create(mailbox_id, item_id));
/*     */   }
/*     */   
/*     */   public static Integer get(int mailbox_id, int folder_id, String davBaseName) {
/* 136 */     return get(DavName.create(mailbox_id, folder_id, davBaseName));
/*     */   }
/*     */   
/*     */   public static synchronized Integer put(DavName davName, int id) {
/* 140 */     ZimbraLog.dav.debug("DavNameMap.put '%s' id=%d", new Object[] { davName, Integer.valueOf(id) });
/* 141 */     idToName.put(MboxAndId.create(davName.mailbox_id, id), davName);
/* 142 */     return (Integer)nameToID.put(davName, Integer.valueOf(id));
/*     */   }
/*     */   
/*     */   public static synchronized void remove(DavName davName) {
/* 146 */     ZimbraLog.dav.debug("DavNameMap.remove '%s'", new Object[] { davName });
/* 147 */     Integer id = (Integer)nameToID.get(davName);
/* 148 */     idToName.remove(davName);
/* 149 */     if (id != null) {
/* 150 */       nameToID.remove(MboxAndId.create(davName.mailbox_id, id.intValue()));
/*     */     }
/*     */   }
/*     */   
/*     */   public static synchronized void remove(int mailbox_id, int item_id) {
/* 155 */     MboxAndId mboxAndId = MboxAndId.create(mailbox_id, item_id);
/* 156 */     ZimbraLog.dav.debug("DavNameMap.remove '%s'", new Object[] { mboxAndId });
/* 157 */     DavName davName = (DavName)idToName.get(mboxAndId);
/* 158 */     if (davName != null) {
/* 159 */       idToName.remove(davName);
/*     */     }
/* 161 */     idToName.remove(mboxAndId);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/DavNames.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */